var util = require('../../../utils/util.js');
var api = require('../../../config/api.js');

var app = getApp();

Page({
  data: {
    typeId: 0,
    collectList: []
  },
  getCollectList() {
    let that = this;
    let user_id = wx.getStorageSync('userId');
    util.request(api.CollectList,{user_id:user_id}).then(function (res) {
      if (res.errno === 0) {
        that.setData({
          collectList: res.data
        });
      }
    });
  },
  onLoad: function (options) {
    wx.setNavigationBarTitle({
      title: "我的收藏"
    })
    this.getCollectList();
  },
  onReady: function () {

  },
  onShow: function () {

  },
  onHide: function () {
    // 页面隐藏

  },
  onUnload: function () {
    // 页面关闭
  },
  deleteCollect:function(e){
    let that=this;
    let goods_id = e.target.dataset.goods_id;
    let user_id = wx.getStorageSync('userId');
    util.request(api.deleteCollect, {goods_id:goods_id,user_id:user_id }).then(function (res) {
      if (res.errno === 0) {
        that.setData({
          collectList: res.data
        });
      }else{
        util.showErrorToast(res.data);
      }
    });

  }

})